#define _CRT_SECURE_NO_WARNINGS 1
#include"my_string.h"

void strlen_test() {
	char arr[20] = "hello world";
	printf("%d\n", my_strlen1(arr));
	printf("%d\n", my_strlen2(arr));
	printf("%d\n", my_strlen3(arr));
}

void strcpy_test() {
	char dest[20] = { 0 };
	char sorc1[] = "hello world";
	char sorc2[] = "friend";
	my_strcpy(dest, sorc1);
	printf("%s\n", dest);
	my_strncpy(dest + 6, sorc2, 6);
	printf("%s\n", dest);
}

void strcmp_test() {
	char str1[] = "hello friend";
	char str2[] = "hello world";
	printf("%d\n", my_strcmp(str1, str2));
	printf("%d\n", my_strncmp(str1, str2, 5));
}

void strcat_test() {
	char str1[30] = { 0 };
	char str2[] = "hello world";
	char str3[] = "hello friend";
	my_strncat(str1, str2, 6);
	my_strcat(str1, str3+6);
	printf(str1);
}


void strtok_test()
{
	char arr[50] = "I.am.learning.strtok";
	char div[] = ".";
	char* ret = NULL;
	for (ret = strtok(arr, div); ret != NULL;ret = strtok(NULL, div)) {
		printf("%s ", ret);
	}
}

void strerror_test()
{
	FILE* p = fopen("test.txt", "r");
	if (p == NULL) {
		printf("%s\n", strerror(errno));
		perror("fopen");
	}
}

void strstr_test() {
	char arr1[] = "qqqqwertaa";
	char arr2[] = "qwert";
	printf(my_strstr(arr1, arr2));
}

void memcpy_test() {
	int arr1[10] = { 1,2,3,4,5 };
	int arr2[5] = { 6,7,8,9,10 };
	my_memcpy(arr1 + 5, arr2, 20);
	my_memmove(arr1 + 5, arr1, 20);
	for (int i = 0;i < 10;i++) {
		printf("%d ", arr1[i]);
	}
}

void memcmp_test()
{
	int arr1[5] = { 1,2,3,4,6 };
	int arr2[5] = { 1,2,3,4,5 };
	printf("%d\n", my_memcmp(arr1, arr2, 16));
	printf("%d\n", my_memcmp(arr1, arr2, 20));
	printf("%d\n", my_memcmp(arr1, arr2+1, 20));
}

void memset_test() 
{
	char arr[20] = "hello world";
	my_memset(arr, 'x', 5);
	my_memset(arr+6, 'y', 5);
	printf(arr);
}

int main()
{
	//strlen_test();
	//strcpy_test();
	//strcmp_test();
	//strcat_test();
	//strtok_test();
	//strerror_test();
	//strstr_test();
	//memcpy_test();
	//memcmp_test();
	//memset_test();
	return 0;
}